package require1;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;

public class GenerateData {
    public static void main(String[] args) {
        //创建文件路径
        File file = new File("dataSet/website.log");
        //准备数据
        Random random = new Random();
        String[] host = {"www.atguigu.com"};
        String[] session_id = {"ABYH6Y4V4SCVXTG6DPB4VH9U123", "XXYH6YCGFJYERTT834R52FDXV9U34",
                "BBYH61456FGHHJ7JL89RG5VV9UYU7", "CYYH6Y2345GHI899OFG4V9U567", "VVVYH6Y4V4SFXZ56JIPDPB4V678"};
        String[] time = {"2017-08-07 08:40:50", "2017-08-07 08:40:51", "2017-08-07 08:40:52", "2017-08-07 08:40:53",
                "2017-08-07 09:40:49", "2017-08-07 10:40:49", "2017-08-07 11:40:49", "2017-08-07 12:40:49"};

        //拼接数据
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < 40; i++) {
            stringBuffer.append(host[0] + "\t" + session_id[random.nextInt(5)]
                    + "\t" + time[random.nextInt(8)] + "\n");
        }

        //检查文件是否存在
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                System.out.println("Create logFile fail !");
            }
        }
        byte[] b = (stringBuffer.toString()).getBytes();
        //写数据到文件
        FileOutputStream fs;
        try {
            fs = new FileOutputStream(file);
            fs.write(b);
            fs.close();
            System.out.println("generate data over");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}


